﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CustomerPreference.aspx.cs" EnableEventValidation="false" Inherits="Main_ServiceInvoice_CustomerPreference" %>

<%@ Register Src="~/User Controls/PageHeading.ascx" TagName="heading" TagPrefix="acc" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="AjaxControl" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <link href="../../Styles/accounts.css" rel="stylesheet" type="text/css" />

    <script language="javascript" type="text/javascript">
        function isNumberKey(contro_id, evt) {
            var charCode = (evt.which) ? evt.which : event.keyCode;

            if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode < 45 || charCode > 47))
                return false;

            if (charCode == 46) {
                var dotcount = document.getElementById(control_id).value.split('.').length - 1;
                if (dotcount >= 1) {
                    return false;
                }
            }
            return true;
        }

        function checkCustomer(id) {
            var ddlCustomer = document.getElementById("ddlCustomer").value;
            var ddlBillFormat = document.getElementById("ddlBillFormat").value;
            if (ddlCustomer == '-Select Customer Name-') {
                alert('Please select customer name !');
                document.getElementById(id).selectedIndex = 0;
                document.getElementById(id).focus();
            }
            else if (ddlBillFormat == '-Select Bill Format-') {
                alert('Please select bill format !');
                document.getElementById(id).selectedIndex = 0;
                document.getElementById(id).focus();
            }
        }
        function checkCustomer2(id) {
            var ddlCustomer = document.getElementById("ddlCustomer").value;
            var ddlBillFormat = document.getElementById("ddlBillFormat").value;
            if (ddlCustomer == '-Select Customer Name-') {
                alert('Please select customer name !');
                document.getElementById(id).selectedIndex = 0;
                document.getElementById(id).focus();
            }
        }
        function checkService() {
            var ddlCustomer = document.getElementById("ddlCustomer").value;
            var ddlBillFormat = document.getElementById("ddlBillFormat").value;
            if (ddlCustomer == '-Select Customer Name-') {
                alert('Please select customer name !');
                document.getElementById("ddlCustomer").focus();
                return false;

            }
            else if (ddlBillFormat == '-Select Bill Format-') {
                alert('Please select bill format !');
                document.getElementById("ddlBillFormat").focus();
                return false;
            }
            else {
                var count = document.getElementById("hiddenControl").value;
                for (var j = 1; j <= count; j++) {
                    var ddlService = document.getElementById("ddlService" + j.toString()).value;
                    var ddlid = document.getElementById("ddlService" + j.toString());
                    if (ddlService == '-select service-') {
                        alert('Please specify service');
                        ddlid.focus();
                        return false;
                        break;
                    }
                }
            }
            return true;
        }

        function NoServiceRepeat(id) {
            var ddl = document.getElementById(id);
            var currentvalue = ddl.options[ddl.selectedIndex].value;
            var count = document.getElementById('hiddenControl').value;
            for (var i = 1; i <= count; i++) {
                var previous = document.getElementById('ddlService' + i.toString());
                var previousvalue = previous.options[previous.selectedIndex].value;
                if (ddl != previous) {
                    if (currentvalue == previousvalue && currentvalue != '0') {
                        alert('Please select unique service !');
                        ddl.selectedIndex = 0;
                        ddl.focus();
                        break;
                    }
                }
            }
        }
    </script>

    <style type="text/css">
        .divheadhr
        {
            float: left;
            width: 70%;
            border-bottom: 1px solid #818181;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="scriptmanger1" runat="server">
    </asp:ScriptManager>
    <div class="divmain" style="width: 100%;">
        <acc:heading ID="PageHead" runat="server" HeadingText="Customer Preference" />
    </div>
    <div style="margin-left: 5%; margin-right: 5%; width: 90%" align="center">
        <span style="color: #f29e08; font-size: 10; font-weight: bold;">
            <asp:Label ID="lblMsg" runat="server" Font-Bold="true"></asp:Label></span>
        <asp:HiddenField ID="hiddenControl" runat="server" Value="1" />
    </div>
    <asp:Panel ID="pnlAddNew" runat="server" Visible="false">
    <div style="width: 90%; padding-left: 5%; padding-right: 5%">
        <table cellpadding="2" class="tablecontent" width="100%">
            <tr>
                <td style="width: 15%">
                    Customer <span style="color: red">*</span>
                </td>
                <td style="width: 35%">
                    <asp:DropDownList ID="ddlCustomer" runat="server" Width="98%" AutoPostBack="true"
                        OnSelectedIndexChanged="ddlCustomer_SelectedIndexChanged">
                    </asp:DropDownList>
                </td>
                <td style="width: 15%">
                    Bill Format <span style="color: red">*</span>
                </td>
                <td style="width: 35%">
                    <asp:DropDownList ID="ddlBillFormat" runat="server" Width="98%" onchange="checkCustomer2(this.id)"
                        OnSelectedIndexChanged="ddlBillFormat_SelectedIndexChanged" AutoPostBack="true">
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td style="width: 15%">
                    Credit Days
                </td>
                <td style="width: 35%" colspan="3" align="left">
                    <asp:TextBox ID="txtCreditDays" runat="server" Width="20%" Text="0" MaxLength="3"
                        CssClass="inputnumber" onKeyPress="return isNumberKey(this.id,event)"></asp:TextBox>
                </td>
            </tr>
        </table>
        <table id="tableFirst" class="tablecontent" runat="server" cellpadding="2" width="100%">
            <tr>
                <td class="headtd" style="width: 45%">
                    Service Name
                </td>
                <%-- <td class="headtd" style="width: 5%" align="center">
                    ...
                </td>--%>
                <td class="headtd" style="width: 25%">
                    Rate
                </td>
                <td class="headtd" style="width: 25%">
                    Unit
                </td>
            </tr>
            <tr>
                <td style="width: 45%">
                    <asp:DropDownList ID="ddlServiceName" runat="server" Width="98%">
                    </asp:DropDownList>
                </td>
                <%-- <td style="width: 5%" align="center">
                    <asp:Button ID="btnServiceMaster" runat="server" Text="..." CssClass="button" Width="98%"
                        OnClientClick="openServiceMaster();" />
                </td>--%>
                <td style="width: 25%">
                    <asp:TextBox ID="txtRate" runat="server" CssClass="input" Width="95%"></asp:TextBox>
                </td>
                <td style="width: 25%">
                    <asp:TextBox ID="txtUnit" runat="server" CssClass="input" Width="95%"></asp:TextBox>
                </td>
            </tr>
        </table>
        <table id="tblDynamic" runat="server" width="100%" border="1">
        </table>
        <table cellpadding="2" class="tablecontent" width="100%">
            <tr>
                <td colspan="4" align="left">
                    <asp:Button ID="btnAddMore" runat="server" Text="Add More" CssClass="button" OnClick="btnAddMore_Click" />&nbsp;&nbsp;
                </td>
            </tr>
        </table>
        <table cellpadding="2" class="tablecontent" width="100%">
            <tr>
                <td align="right" style="width: 100%;">
                    <asp:Button ID="btnSave" runat="server" Text="Save" CssClass="button" OnClick="btnSave_Click"
                        OnClientClick="return checkService()" />&nbsp;&nbsp;
                    <asp:Button ID="btnClose" runat="server" Text="Close" CssClass="button" OnClick="btnClose_Click" />&nbsp;&nbsp;
                </td>
            </tr>
        </table>
    </div>
    </asp:Panel>
    <asp:Panel ID="pnlView" runat="server" Visible="false">
    <div style="width: 60%; margin-left: 20%; margin-right: 20%; margin-top:15px;" >
    <asp:GridView ID="grdCustPref" runat="server" CssClass="gridview" Width="100%" AlternatingRowStyle-CssClass="gridview_alternate"
            AllowPaging="true" PageSize="10" AutoGenerateColumns="False" DataKeyNames="CUSTOMERPREID,FORMATID"
            OnRowCommand="grdCustPref_RowCommand" OnPageIndexChanging="grdCustPref_PageIndexChanging"
            OnRowDataBound="grdCustPref_OnRowDataBound">
            <Columns>
                <asp:TemplateField>
                    <HeaderTemplate>
                        Customer Name
                    </HeaderTemplate>
                    <ItemTemplate>
                        <asp:Literal ID="ltCustomerName" runat="server" Text='<%#Eval("LNAME") %>'></asp:Literal>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <HeaderTemplate>
                        Bill Format Name
                    </HeaderTemplate>
                    <ItemTemplate>
                        <asp:Literal ID="ltBillFormatName" runat="server" Text='<%#Eval("FORMATNAME") %>'></asp:Literal>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <HeaderTemplate>
                        Credit Days
                    </HeaderTemplate>
                    <ItemTemplate>
                        <asp:Literal ID="ltCreditDays" runat="server" Text='<%#Eval("CRDAYS") %>'></asp:Literal>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <HeaderTemplate>
                        View
                    </HeaderTemplate>
                    <ItemTemplate>
                        <asp:LinkButton ID="lnkView" runat="server" Text="View" CommandArgument='<%#Eval("CUSTOMERPREID")%>'
                            CommandName="viewPreference"></asp:LinkButton>
                        <asp:Panel ID="Panel1" runat="server" Style="display: none" BorderColor="#3a6e20"
                            BorderWidth="2px" CssClass="modalPopup" Width="600px">
                            <div style="float: right;">
                                <asp:LinkButton ID="lnkBtnClose" runat="server" Text="Close"></asp:LinkButton></div>
                            <b>Customer - </b>
                            <asp:Label ID="lblCustomer" runat="server" Text='<%#Eval("LNAME") %>'></asp:Label><br />
                            <b>Bill Format Name-</b>
                            <asp:Label ID="lblBillFormat" runat="server" Text='<%#Eval("FORMATNAME")%>'></asp:Label><br />
                            <asp:GridView ID="grdDetails" runat="server" Width="98%" OnRowDataBound="grdDetails_OnRowDataBound"
                                CssClass="gridview" AlternatingRowStyle-CssClass="gridview_alternate">
                            </asp:GridView>
                        </asp:Panel>
                        <ajaxcontrol:modalpopupextender id="MPE_ViewServiceUnitDetail" runat="server" cancelcontrolid="lnkBtnClose"
                            targetcontrolid="lnkView" backgroundcssclass="modalBackground" popupcontrolid="Panel1" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <HeaderTemplate>
                        Edit
                    </HeaderTemplate>
                    <ItemTemplate>
                    <asp:LinkButton id="lnkEdit" runat="server" CommandArgument='<%#Eval("CUSTOMERPREID") %>'
                            CommandName="editPreference"><img src="../../Menu/images/Edit_user.png" /></asp:LinkButton> 
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </div>
    </asp:Panel>
    </form>
</body>
</html>
